<?php
/*
 *直播
*/
namespace App\Http\Controllers;

use App\Service\LiveService;
use App\Validation\ListValidation;
use App\Validation\LiveStartValidation;
use App\Validation\LiveCloseValidation;
use App\Validation\DeleteValidation;	

class LiveController extends BaseController
{
	//列表
    public function indexAction()
    {
		$raw = $this->validation(new ListValidation,$this->request->getJsonRawBody());
		$data = LiveService::getList($raw);
		return  $this->echoJson(['total'=>LiveService::count(),'list'=>$data]);
    }
	
	//回播列表
    public function playAction()
    {
		$this->getUser(false);
		$raw = $this->validation(new ListValidation,$this->request->getJsonRawBody());
		if($this->user && empty($raw->host_id)){
			$raw->host_id = $this->user->member_id;
		}
		$data = LiveService::getPlayBackList($raw);
		return  $this->echoJson(['total'=>LiveService::countPlay($raw->host_id),'list'=>$data]);
    }	
	
	//直播详情
    public function detailAction()
    {
		$id = $this->dispatcher->getParam('id');
		$data = LiveService::getInfo($id);
		return  $this->echoJson($data);
    }
	
	//获取房间号
    public function roomAction()
    {
		return  $this->echoJson(['room_id'=>1,'video_id'=>1001]);
    }
	
	//我要直播 队列处理
    public function startAction()
    {
		$user = $this->getUser();
		$raw = $this->validation(new LiveStartValidation,$this->request->getJsonRawBody());
		LiveService::save($raw);
		return  $this->echoJson('ok');
    }	
	
	//关闭直播
    public function closeAction()
    {
		$user = $this->getUser();
		$raw = $this->validation(new LiveCloseValidation,$this->request->getJsonRawBody());
		$data = LiveService::close($raw);
		return  $this->echoJson($data);
    }

    /**
     * [replayAction 回播]
     * @return [type] [description]
     */
    public function replayAction()
    {
    	$user = $this->getUser();
    	$id = $this->dispatcher->getParam('id');
		$data = LiveService::getReplay($id);
		return  $this->echoJson($data);
    }

    /**
	 * [deleteAction 删除]
	 * @return [type] [description]
	 */
	public function deleteAction()
	{
		$this->getUser();
		$raw = $this->validation(new DeleteValidation, $this->request->getJsonRawBody());
		$data = LiveService::forever($raw->id);
		return $this->echoJson('ok');
	}	
	
}
